Conversation
This commit strips tag prefix before sorting semver tags and re-adds it to result.
| # find latest ref matching prefix | ||
| local ref=$( | ||
| echo "$refs" \ | ||
| | sed -E -n "s%.*refs/tags/${prefix-v?}([0-9]+\.[0-9]+\.[0-9]+)\$%\1%p" \ | ||
| | grep -v '\^{}$' \ | ||
| | sort -t. -k1,1nr -k2,2nr -k3,3nr \ | ||
| | head -n1 | ||
| ) | ||
| if [ -n "$ref" ]; then | ||
| echo "$prefix$ref" |
There was a problem hiding this comment.
I think one case it doesn't handle is when no prefix is provided but tags start with v. Then $prefix will be an empty string and v won't be part of returned ref.
There was a problem hiding this comment.
Also it seems like ${prefix-v?} will only fall back to v? when it's not set which I believe will never be true in this case. It doesn't fall back when $prefix is empty string.
There was a problem hiding this comment.
I see, it would need to be ${prefix:-v?} to work as expected.
The function might return invalid tag names then, however as the current approach doesn't preserve individual prefixes to be prepended again after sorting.
Those bash scripts actually seem rather naive overall. Maybe the only fix to make without putting too much effort into them, would be to remove :v? to explicitly disable automatic v prefix stripping.
It is IMHO not too much of a hassle to expect to explicitly provide it as prefix on demand.
As current implementation fulfills this behavior, I don't see a reason for another release.
Fixes #279
This commit...
sort ...work as expected.